package splug.cjk;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import splug.cjk.packet.FriendPacket;

public class FriendRequestAccept extends Thread{
	
	private OutputStream os;
	private String id;
	private String you;
	
	public FriendRequestAccept(OutputStream os, String id, String you) {
		super();
		this.os = os;
		this.id = id;
		this.you = you;
	}

	public void run(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/carpool?useUnicode=true&characterEncoding=euckr","root","apmsetup");
			Statement stmt = conn.createStatement();

			String query1 = "update friend set accept = 1 where f = '" + you + "' and t = '" + id + "';";
			String query2 = "insert into `carpool`.`friend`(f, t, accept) values('" + id + "' , '" + you + "', " + 1 + ");";

			stmt.execute("SET CHARACTER SET euckr");
			stmt.execute("set names euckr");

			stmt.executeUpdate(query1);
			stmt.executeUpdate(query2);
			
			os.write('1');
			os.flush();
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
